package com.example.travelplan.app;

/**
 * Created by jonas on 19/06/2014.
 */
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.travelplan.app.dominio.Controller;
import com.example.travelplan.app.dominio.TipoLugar;

public class tabListTipoLugarActivity extends Activity {

    MeuAdaptador_Atual listAdapter;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tablisttipolugar);

        listAdapter = new MeuAdaptador_Atual();

        ListView listView = (ListView)findViewById(R.id.textViewDataRoteiro);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setAdapter(listAdapter);

        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {

                TipoLugar tipoLugar = listAdapter.getTipoLugar(arg2);

                Toast.makeText(tabListTipoLugarActivity.this, tipoLugar.getM_nome(),Toast.LENGTH_LONG).show();

            }
        });
    }


    public class MeuAdaptador_Atual extends BaseAdapter {

        List<TipoLugar> tipoLugarList = Controller.getInstance().obterTipoLugar();
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return tipoLugarList.size();
        }

        @Override
        public TipoLugar getItem(int arg0) {
            // TODO Auto-generated method stub
            return tipoLugarList.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {

            if(arg1==null)
            {
                LayoutInflater inflater = (LayoutInflater) tabListTipoLugarActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                arg1 = inflater.inflate(R.layout.listitem_tipolugar, arg2,false);
            }

            TextView atividades = (TextView)arg1.findViewById(R.id.textViewDataRoteiro);

            TipoLugar tipoLugar = tipoLugarList.get(arg0);

            atividades.setText(tipoLugar.getM_nome());

            return arg1;
        }

        public TipoLugar getTipoLugar(int position)
        {
            return tipoLugarList.get(position);
        }

    }

}